package com.magesti.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.magesti.DAO.DaoFactory;
import com.magesti.DAOinterface.HistoriqueInterfaceDAO;
import com.magesti.DAOinterface.OperationInterfaceDAO;
import com.magesti.beans.Operation;
import com.magesti.exception.DAOException;
import com.magesti.ressource.Global;
import com.magesti.ressource.ServletGlobal;
@SuppressWarnings({ "serial" }) // pour eviter le warning de "Global
//Cette servlet sert de prototye pour creer de nouveaux servlet !

public class Acceuil extends HttpServlet {

	private HistoriqueInterfaceDAO historiqueDAO;
	private OperationInterfaceDAO operationDAO;

	public void init() throws ServletException {
		DaoFactory f = ((DaoFactory) getServletContext().getAttribute(
				Global.ATT_CONTEXT_DAO_FACTORY));
		historiqueDAO = f.getHistoriqueDAO();
		operationDAO = f.getOperationDAO();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		int id_op = ServletGlobal.checkIdOperation(request);
		List<Operation> listOperationMessage = null;

		try {
			listOperationMessage = historiqueDAO.create_LastHistorique(10);			

		} catch (DAOException e) {
			e.printStackTrace();
		}	//listeOperationMessage
		
		request.setAttribute(Global.ATT_REQUEST_LISTE_OPERATION_MESSAGE,listOperationMessage);
		
		this.getServletContext().getRequestDispatcher(Global.VUE_JSP_ACCEUIL).forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// this.getServletContext().getRequestDispatcher(Global.VUE_EXEMPLE).forward(request,response);
	}

}
